// 中心充电桩远程充电机控制设置
const _ = require('lodash');
exports.send = (socket, data, core) => {
  let publisher = core.getService('redis').getClient();
  // 要控制充电模块的数量
  const count = 1;
  const userIdBuf = core.createIntBuffer(2, 2);
  const cmdIndexBuf = core.createIntBuffer(1, 2);
  const typeBuf = core.createIntBuffer(2, 1);
  const countBuf = core.createIntBuffer(count, 1);
  let tagers = [];
  _.times(count, () => {
    // 控制充电模块的编号和状态
    let gunNumber = parseInt(data.port), param = 512; //停机
    tagers.push(core.createIntBuffer(gunNumber, 1));
    tagers.push(core.createIntBuffer(param, 2));
  })
  // const date = core.date.date2Buffer(new Date());
  // // 监听 0x52 的回复
  // socket.once(`0x52-${userIdBuf.toString('hex')}-${cmdIndexBuf.toString('hex')}`, (data) => {
  //   callback && callback(data);
  // })
  console.log(core.concat([userIdBuf, cmdIndexBuf, typeBuf, countBuf, ...tagers]));
  socket.once(`0x15-${userIdBuf.toString('hex')}-${cmdIndexBuf.toString('hex')}`, (info) => {
    publisher.publish('commandback', JSON.stringify({
      result: { data: info },
      callback: data.callback,
    }));
  });
  socket.sendCommands(0x05, core.concat([userIdBuf, cmdIndexBuf, typeBuf, countBuf, ...tagers]));
}
